layui.use(['laydate','form','table','laytpl','layer','element','gcate'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var laytpl = layui.laytpl;
	var layer = layui.layer;
	var element = layui.element;
	var gcate = layui.gcate;
	/*@默认选择*/
	var cate_id = $('.layui-this').attr('ty')
	ifTab()
	/*@监听选项卡*/
	element.on('tab(tab-btn)', function(data){
		let elem = data.elem
		cate_id = $(elem).find('li').eq(data.index).attr('ty')
		let html = '';
		ifTab()
	})
	/*@选项卡判断*/
	function ifTab(){
		if($.inArray(Number(cate_id), parent.layui.cate) >=0){/*采购*/
			html = $('#cg-box').html()
		}else{/*非采购*/
			html = $('#ncg-box').html()
		}
		$('#tab-content-box').html(html)
		form.render("select");
	}
	/*@产品分类*/
	gcate.form.g_cate('select', '/staff/goods/sun_cate');
	/*@计算支出总额*/
	num_price = function(obj,field,total){
		let v = $(obj).val()
		let br = $('input[name="'+field+'"]').val()
		let money = (Number(v*100) * Number(br*100))/10000;
		$('input[name="'+total+'"]').val(money)
	}
	/*@验证*/
	form.verify({
		money: function(value){
			let num = $('input[name="number"]').val()
			let price = $('input[name="buying_price"]').val()
			if(Number(value) != Number(num) * Number(price)){
				return '支出总额不等于采购数量*进货单价';
			}
		}
	})
	/*@提交*/
	form.on('submit(query_btn)',function(data){
		objData = data.field
		objData.expend_cate_id = cate_id
		$.post('', objData, function(msg){
			if(msg.code !== 1){
				layer.msg(msg.msg, {icon: 5});
			}else{
				layer.msg(msg.msg, {icon: 6}, function(){
					parent.location.reload()
				})
			}
		})
	})
	
});